<template>
  <div class="bs" style="padding-bottom: 120px">
    <!-- 查询条件 -->
    <Search ref="form" @search="initTable" />
    <!-- table组件 -->
    <DeptTable ref="table" v-loading="loading" :data-list="dataList" @search="initTable" />
  </div>
</template>
<script>
import Search from './components/Search'
import DeptTable from './components/Table'
import { getDepts } from '@/api/system/dept'
// import Jop from './components/Jop'
export default {
  components: { Search, DeptTable },
  data() {
    return {
      editData: {},
      dataList: [],
      title: '',
      loading: false
    }
  },
  mounted() {
    this.initTable()
  },
  methods: {
    initTable() {
      this.loading = true
      const params = this.$refs.form.query
      getDepts({ ...params }).then(res => {
        this.dataList = res.list
        setTimeout(() => {
          this.loading = false
        }, 500)
      }, () => {
        this.loading = false
      })
    },
    callBack(v, d, n, t) {
      this[v](d, n, t)
    },
    addJob(t) {
      this.editData = {}
      this.title = t
      this.showJop = true
    },
    editDept(d, t) {
      this.editData = d
      this.title = t
      this.showJop = true
    },
    // updateStatus
    updateStatus(v) {
      this.$confirm(`此操作将 ${v.enabled ? '启用' : '停用'} ${v.name}, 是否继续？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // edit({ ...v }).then(res => {
        //   this.$message.success('操作成功~')
        //   this.$refs.table.initTable()
        // }).catch(() => {
        //   v.enabled = !v.enabled
        // })
      }).catch(() => {
        v.enabled = !v.enabled
      })
    },
    // delet
    delet(row) {
      this.$confirm('确定要删除该岗位吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // del([row.id]).then(res => {
        //   this.$message.success('操作成功~')
        //   this.$refs.table.initTable()
        // })
      })
    }
  }
}
</script>
